var SanPoss = (function ($, undefined) {
    var messager = (function () {
        var dialogId = "#dialog_messager",
            dialogContentId = "#dialog_messager_content",
            dialogHtml = '<div style="position:absolute;z-index:9999;background:#000;border-radius:0.2em;filter:alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity: 0.7;opacity: 0.7;" id="dialog_messager">' +
                    '<p style="color:#FFF;font-size:12px;padding:10px 15px;margin:0px;" id="dialog_messager_content"></p></div>';
        var returnUrl = "";
        return {
            show: function (content, url) {
                if ($(dialogId).length <= 0) {
                    $(dialogHtml).appendTo(document.body);//添加到body
                }
                $(dialogContentId).html(content);
                var bodyH = $(window).height();
                var bodyW = $(window).width();
                var promptBoxH = $(dialogId).height();
                var promptBoxW = $(dialogId).width();
                var bTop = (bodyH - promptBoxH) / 2;
                var bLeft = (bodyW - promptBoxW) / 2;
                $(dialogId).css('top', bTop + $(document).scrollTop());
                $(dialogId).css('left', bLeft);
                returnUrl = url;
                setTimeout(this.close, 1500);
            },
            close: function () {
                $(dialogId).remove();
                if (returnUrl) {
                    location.href = returnUrl;
                }
            }
        };
    })();
    var sms = (function () {
        var isSending = false;
        return {
            send: function (mobile, type, fnSuccess, fnError) {
                if (isSending) {
                    return false;
                }
                isSending = true;
                $.ajax({
                    url: "/common/SendSmsCode",
                    type: 'POST',
                    data: { mobile: mobile, type: type },
                    dataType: 'json',
                    cache: false,
                    success: function (result) {
                        if (result.Success) {
                            if (fnSuccess) {
                                fnSuccess(result);
                            }
                            isSending = false;
                        } else {
                            if (fnError) {
                                fnError(result);
                            } else {
                                alert(result.Message);
                            }
                            isSending = false;
                        }
                    },
                    error: function () {
                        if (fnError) {
                            fnError(result);
                        } else {
                            alert("当前网络出错，请稍后再试");
                        }
                        isSending = false;
                    }
                });
                return false;
            }
        };
    })();
    var isWeiXin = (function() {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    });
    return {
        messager: messager,
        sms: sms,
        isWeiXin: isWeiXin
    };
})(jQuery);
